package com.ruoyi.common.model.excel;

import com.ruoyi.common.utils.excl.model.ImportErrorInfo;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ValidateBatchRes<T> {

    /** 成功条数 **/
    private Integer successNum = 0;

    /** 失败条数 **/
    private Integer failAmount = 0;

    /** 成功标记 **/
    private Boolean successFlag = true;

    /**
     * 失败内容
     */
    private List<ImportErrorInfo<T>> errorInfoList = new ArrayList<>();

    public boolean addErrorInfo(Integer orderNum, String message, T data) {
        if (successFlag) {
            successFlag = false;
        }
        ImportErrorInfo<T> importErrorInfo = new ImportErrorInfo<>();
        importErrorInfo.setOrderNum(orderNum);
        importErrorInfo.setMessage(message);
        importErrorInfo.setData(data);
        failAmount++;
        return errorInfoList.add(importErrorInfo);
    }

    public void success() {
        successNum++;
    }
}
